package com.humanmonth.home.component.page.portal
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.collections.ArrayCollection;
	import mx.controls.TileList;
	import mx.controls.Tree;
	import mx.core.Application;
	import mx.events.DragEvent;
	import mx.events.FlexEvent;
	import mx.managers.DragManager;
	
	public class ContentAs extends Content
	{
		public function ContentAs()
		{
			super();
			this.addEventListener(FlexEvent.CREATION_COMPLETE,myInit);
		}
		[Bindable]
		public var portletNames:ArrayCollection=new ArrayCollection([{title:"最新邮件"},{title:"最新公告"}]);
		private function myInit(event:Event):void{
			this.portlet.dataProvider=this.portletNames;
			this.initDragDrop();
			this.addEventListener(MouseEvent.MOUSE_DOWN,enableSelfDragdrop);
			Application.application.addEventListener(MouseEvent.MOUSE_UP,disableSelfDrag);
		}
		
		private function enableSelfDragdrop(event:MouseEvent):void{
			this.portlet.dragEnabled=true;
			this.portlet.dropEnabled=true;
			this.portlet.dragMoveEnabled=true;
		}
		
		private function disableSelfDrag(event:MouseEvent):void{
			this.portlet.dragEnabled=false;
			this.portlet.dropEnabled=false;
			this.portlet.dragMoveEnabled=false;
		}
		
		private function initDragDrop():void{
			this.portlet.addEventListener(DragEvent.DRAG_ENTER,judgeIfAccessDrop);
			this.portlet.addEventListener(DragEvent.DRAG_DROP,dropHandler);
		}
		
		
		private function judgeIfAccessDrop(event:DragEvent):void{
	//		if(event.dragSource.hasFormat(CatalogTreeAs.TreeFormat)){
				DragManager.acceptDragDrop(TileList(event.currentTarget));
//			}
		}
		
		private function dropHandler(event:DragEvent):void{
		if(event.dragSource.hasFormat(CatalogTreeAs.TreeFormat)){
		var cname:String=Tree(event.dragInitiator).selectedItem.@cname;
		this.portletNames.addItem({title:cname});
		}
		}
	}
}